package top.zlcode.system.controller.question;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.zlcode.common.core.controller.BaseController;
import top.zlcode.common.core.domain.R;
import top.zlcode.common.core.domain.TableDataInfo;
import top.zlcode.system.domain.question.dto.QuestionAddDTO;
import top.zlcode.system.domain.question.dto.QuestionEditDTO;
import top.zlcode.system.domain.question.dto.QuestionQueryDTO;
import top.zlcode.system.domain.question.vo.QuestionDetailVO;
import top.zlcode.system.service.question.IQuestionService;



@RestController
@RequestMapping("/question")
@Tag(name = "题目管理接口")
public class QuestionController extends BaseController {

    @Autowired
    private IQuestionService questionService;

    @GetMapping("/list")
    @Operation(summary = "查询题目列表", description = "根据 questionQueryDTO 参数查询题目")
    public TableDataInfo list(QuestionQueryDTO questionQueryDTO) {
        return getTableDataInfo(questionService.list(questionQueryDTO));
    }

    @PostMapping("/add")
    @Operation(summary = "管理员新增题目", description = "根据 questionAddDTO 参数新增题目")
    public R<Void> add(@RequestBody QuestionAddDTO questionAddDTO) {
        return toR(questionService.add(questionAddDTO));
    }

    @GetMapping("/detail")
    @Operation(summary = "查看题目详情信息", description = "根据 id 查询题目详情")
    public R<QuestionDetailVO> detail(@RequestParam Long questionId) {
        return R.ok(questionService.detail(questionId));
    }

    @PutMapping("/edit")
    @Operation(summary = "修改题目信息", description = "根据 questionEditDTO 修改题目信息")
    public R<Void> edit(@RequestBody QuestionEditDTO questionEditDTO) {
        return toR(questionService.edit(questionEditDTO));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除题目", description = "根据 questionEditDTO 删除题目")
    public R<Void> delete(@RequestParam Long questionId) {
        return toR(questionService.delete(questionId));
    }

}
